<template>
  <div class="nav-header">
    <el-icon
      class="nav-header_icon"
      v-if="isFold"
      @click="handleFoldClick"
      :size="size"
    >
      <Expand />
    </el-icon>
    <el-icon
      class="nav-header_icon"
      v-else
      @click="handleFoldClick"
      :size="size"
    >
      <Fold />
    </el-icon>
    <div class="content">
      <navBreadCrumb :breadcrumbs="breadcrumbs" />
      <div><userInfo /></div>
    </div>
  </div>
</template>

<script>
import { useRoute } from "vue-router";
import { pathMapTobread } from "@/utils/map-menus.js";
import navBreadCrumb from "./nav-breadcrumb.vue";
import userInfo from "./user-info.vue";
import { ref, computed } from "vue";
import { useStore } from "vuex";
import { Fold, Expand } from "@element-plus/icons-vue";
export default {
  components: {
    Fold,
    Expand,
    userInfo,
    navBreadCrumb,
  },
  emits: ["foldchange"],
  setup(props, { emit }) {
    const size = "20px";
    const isFold = ref(false);
    const store = useStore();

    const breadcrumbs = computed(() => {
      const route = useRoute();
      const currentPath = route.path;
      const userMenu = store.state.login.userMenu;
      return pathMapTobread(userMenu, currentPath);
    });

    const handleFoldClick = () => {
      isFold.value = !isFold.value;
      emit("foldchange", isFold.value);
    };
    return {
      size,
      handleFoldClick,
      isFold,
      breadcrumbs,
    };
  },
};
</script>

<style lang="scss" scope>
.nav-header {
  display: flex;
  width: 100%;
  align-items: center;
  &_icon {
    cursor: pointer;
  }
  .content {
    display: flex;
    justify-content: space-between;
    flex: 1;
    padding: 0 20px;
    font-weight: 550;
    align-items: center;
    font-size: 15px;
  }
}
</style>
